const { BrowserWindow, app, globalShortcut, ipcMain, shell, screen } = require('electron')
const path = require('path')
const express = require('express')
const { log } = require('console')

//2.创建应用
const app1 = express()

//3.设置请求

const createWindow = () => {
  const { width, height } = screen.getPrimaryDisplay().workAreaSize
  const mainWindow = new BrowserWindow({
    width: 64,
    height: 448,
    minHeight: 64,
    minWidth: 448,
    maxHeight: 64,
    maxWidth: 448,
    // x: width - 400,
    // y: height - 200,
    alwaysOnTop: true,
    frame: false,
    transparent: true,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
      nodeIntegration: true,

      sandbox: false
    }
  })
  mainWindow.setAspectRatio(7)
  console.log(__dirname)
  mainWindow.loadFile(path.resolve(__dirname, 'index.html'))
  // mainWindow.webContents.openDevTools();

  //4.开启服务器
  app1.listen(8989, () => {
    console.log('server is running at http://localhost')
  })
  app1.get('/', (req, res) => {
    res.send(200)
    mainWindow.webContents.send('counter-value', req.query.key)
    // BrowserWindow.fromWebContents(_event.sender).send('counter-value', req.query.key.split('-')[0]);
  })
}
require('./ipcMain')
app.whenReady().then(() => {
  createWindow()
})

ipcMain.on('counter-value', (_event, value) => {
  console.log(value)
})
